package com.hnucm.c201901020121.Activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.hnucm.c201901020121.Fragment.Home.HomeFragment;
import com.hnucm.c201901020121.R;
import com.hnucm.c201901020121.Utils.Bmob.BmobTask;
import com.hnucm.c201901020121.Utils.OtherUtils.GlideEngine;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.listener.OnResultCallbackListener;

import org.xutils.common.Callback;
import org.xutils.common.util.LogUtil;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.util.List;
import java.util.UUID;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

import static com.hnucm.c201901020121.Activity.LoginAct.currentUser;

public class EditTaskAct extends AppCompatActivity {
    TextView lobbyPublish, homePublish, label, title, taskTime, audioTime, amount, garaMoney, step1, step2, step3, first, second, third, te1, step1Detail, step3Detail;
    ImageView back, taskTimeImg, audioTimeImg, addImg;
    Button publish;

    final int REQUEST_PICK_IMAGE = 11101;
    private PopupWindow popupWindow;
    private WindowManager.LayoutParams params;
    private View pop;
    private boolean mIsShowing = false;
    Boolean audioTimeText, taskTimeText;
    private String mlabel, realPathFromUri, imgFile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_task);
        initView();
        dataInit();
        x.Ext.init(getApplication());
        addImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PictureSelector.create(EditTaskAct.this)
                        .openGallery(PictureMimeType.ofImage())
                        .imageEngine(GlideEngine.createGlideEngine())
                        .forResult(new OnResultCallbackListener<LocalMedia>() {
                            @Override
                            public void onResult(List<LocalMedia> result) {
                                // onResult Callback

                                for (LocalMedia localMedia : result) {
                                    Log.i("MainActivity", localMedia.getPath());
                                }
                                //todo 显示图片
                                Glide.with(EditTaskAct.this).load(Uri.fromFile(new File(result.get(0).getRealPath())))
                                        .into(addImg);
                                realPathFromUri = result.get(0).getRealPath();

                                Log.i("upimg", realPathFromUri);

                            }

                            @Override
                            public void onCancel() {
                                // onCancel Callback
                            }
                        });
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        publish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                insertTaskDate();
            }
        });
        taskTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                te1 = pop.findViewById(R.id.textView);
                taskTimeText = true;
                if (popupWindow == null) {
                    initPopup();
                    te1.setText("请选择任务时间");
                }
                if (!mIsShowing) {
                    te1.setText("请选择任务时间");
                    params.alpha = 0.7f;
                    getWindow().setAttributes(params);
                    popupWindow.showAtLocation(findViewById(R.id.layout_main), Gravity.BOTTOM, 0, 0);
                    mIsShowing = true;
                }
            }
        });
        audioTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                te1 = pop.findViewById(R.id.textView);
                audioTimeText = true;
                te1.setText("请选择审核时间");
                if (popupWindow == null) {
                    initPopup();
                }
                if (!mIsShowing) {
                    params.alpha = 0.7f;
                    getWindow().setAttributes(params);
                    popupWindow.showAtLocation(findViewById(R.id.layout_main), Gravity.BOTTOM, 0, 0);
                    mIsShowing = true;
                }
            }
        });
        audioTimeImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                te1 = pop.findViewById(R.id.textView);
                audioTimeText = true;
                te1.setText("请选择审核时间");
                if (popupWindow == null) {
                    initPopup();
                }
                if (!mIsShowing) {
                    params.alpha = 0.7f;
                    getWindow().setAttributes(params);
                    popupWindow.showAtLocation(findViewById(R.id.layout_main), Gravity.BOTTOM, 0, 0);
                    mIsShowing = true;
                }
            }
        });
        taskTimeImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                te1 = pop.findViewById(R.id.textView);
                taskTimeText = true;
                if (popupWindow == null) {
                    initPopup();
                    te1.setText("请选择任务时间");
                }
                if (!mIsShowing) {
                    te1.setText("请选择任务时间");
                    params.alpha = 0.7f;
                    getWindow().setAttributes(params);
                    popupWindow.showAtLocation(findViewById(R.id.layout_main), Gravity.BOTTOM, 0, 0);
                    mIsShowing = true;
                }
            }
        });
        homePublish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                homePublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_se));
                homePublish.setTextColor(Color.parseColor("#FFFFFF"));
                lobbyPublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_un));
                lobbyPublish.setTextColor(Color.parseColor("#F7B04C"));
            }
        });
        lobbyPublish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                homePublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_un));
                homePublish.setTextColor(Color.parseColor("#F7B04C"));
                lobbyPublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_se));
                lobbyPublish.setTextColor(Color.parseColor("#FFFFFF"));
            }
        });
    }

    void initView() {
        label = findViewById(R.id.editTextTextPersonName6);
        title = findViewById(R.id.editTextTextPersonName);
        taskTime = findViewById(R.id.textView114);
        audioTime = findViewById(R.id.textView115);
        amount = findViewById(R.id.editTextTextPersonName4);
        garaMoney = findViewById(R.id.editTextTextPersonName5);
        step1 = findViewById(R.id.step1);
        step2 = findViewById(R.id.step2);
        step3 = findViewById(R.id.step3);
        step3Detail = findViewById(R.id.step4);
        step1Detail = findViewById(R.id.step1detail);
        lobbyPublish = findViewById(R.id.textView109);
        homePublish = findViewById(R.id.textView111);
        taskTimeImg = findViewById(R.id.imageView56);
        audioTimeImg = findViewById(R.id.imageView64);
    }

    private void dataInit() {
        audioTimeText = false;
        taskTimeText = false;
        homePublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_se));
        homePublish.setTextColor(Color.parseColor("#FFFFFF"));
        lobbyPublish.setBackground(getResources().getDrawable(R.drawable.edit_task_button_un));
        lobbyPublish.setTextColor(Color.parseColor("#F7B04C"));
        mlabel = getIntent().getStringExtra("label");
        label.setText(mlabel);
        back = findViewById(R.id.imageView48);
        params = getWindow().getAttributes();
        pop = View.inflate(this, R.layout.popu, null);
        params.width = pop.getContext().getResources().getDisplayMetrics().widthPixels;
        params.height = pop.getContext().getResources().getDisplayMetrics().heightPixels; // 如果不是全屏要送去状态栏高度
        getWindow().setAttributes(params);
        first = findViewById(R.id.imageView54);
        first.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC);
        second = findViewById(R.id.imageView55);
        second.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC);
        third = findViewById(R.id.imageView58);
        third.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC);
        publish = findViewById(R.id.button2);
        addImg = findViewById(R.id.img);
        if (mlabel.equals("中通快递") || mlabel.equals("圆通快递") || mlabel.equals("韵达快递") || mlabel.equals("顺丰快递") || mlabel.equals("申通快递") || mlabel.equals("京东快递") || mlabel.equals("百世快递") || mlabel.equals("其他快递")) {
            step1.setText("姓名");
            step2.setText("快递取件码截图");
            step3.setText("快递送达位置");
        } else if (mlabel.equals("苹果") || mlabel.equals("香蕉") || mlabel.equals("梨子") || mlabel.equals("橘子") || mlabel.equals("火龙果") || mlabel.equals("水果捞") || mlabel.equals("西瓜") || mlabel.equals("其他水果")) {
            step1.setText("水果重量");
            step2.setText("任务说明");
            step3.setText("水果放置位置");
        } else if (mlabel.equals("美团") || mlabel.equals("饿了么")) {
            step1.setText("外卖位置");
            step2.setText("外卖订单详情");
            step3.setText("外卖送达位置");
        } else if (mlabel.equals("带饭")) {
            step1.setText("餐厅位置");
            step2.setText("任务说明");
            step3.setText("送达位置");
        } else if (mlabel.equals("拾物")) {
            step1.setText("物品位置");
            step2.setText("任务说明");
            step3.setText("送达位置");
        } else {
            step1.setText("任务信息");
            step2.setText("任务说明");
            step3.setText("任务要求");
        }
    }

    private void insertTaskDate() {
        int rec;
        if (lobbyPublish.getCurrentTextColor() == Color.parseColor("#F7B04C")) {
            rec = 0;
        } else {
            rec = 1;
        }

            uploadfile(realPathFromUri);

        BmobTask bmobTask = new BmobTask();
        bmobTask.setRecom(rec);
        bmobTask.setAmount(amount.getText().toString());
        bmobTask.setLabel(label.getText().toString());
        bmobTask.setTitle(title.getText().toString());
        bmobTask.setTaskTime(taskTime.getText().toString());
        bmobTask.setAudioTime(audioTime.getText().toString());
        bmobTask.setGaraMount(garaMoney.getText().toString());
        bmobTask.setStep1(step1.getText().toString());
        bmobTask.setStep2(step2.getText().toString());
        bmobTask.setStep3(step3.getText().toString());
        bmobTask.setType(1);
        bmobTask.setHeadimg(currentUser.getHeadimg());
        bmobTask.setPublisherId(currentUser.getObjectId());
        bmobTask.setState("待领取");
        bmobTask.setStep1Detail(step1Detail.getText().toString());
        bmobTask.setStep3Detail(step3Detail.getText().toString());
        bmobTask.setImg("http://192.168.43.173:8080/FileUpload/upload/" + imgFile);
        //备用ip：192.168.43.173
        bmobTask.save(new SaveListener<String>() {
            @Override
            public void done(String s, BmobException e) {
                if (e == null) {
                    Toast.makeText(EditTaskAct.this, "发布成功", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(EditTaskAct.this, HomeFragment.class);
                    startActivity(intent);
                } else {
                    Log.i("EditTaskAck","获取数据失败");
                }
            }
        });
    }

    private void initPopup() {
        pop = View.inflate(this, R.layout.popu, null);
        popupWindow = new PopupWindow(pop, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(false);
        popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));
        popupWindow.setAnimationStyle(R.style.anim_menu_bottombar);
        mIsShowing = false;
        pop.setFocusableInTouchMode(true);
    }

    @SuppressLint("ResourceAsColor")
    public void onClick_(View view) {
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("30分钟");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("30分钟");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_a(View view) {
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("1小时");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("1小时");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_b(View view) {
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("2小时");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("2小时");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_c(View view) {
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("4小时");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("4小时");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_d(View view) {
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("6小时");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("6小时");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_e(View view) {
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("12小时");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("12小时");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_f(View view) {
        te1 = pop.findViewById(R.id.textView2);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView3);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView1);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView4);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView5);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = pop.findViewById(R.id.textView6);
        te1.setTextColor(Color.parseColor("#7D7D7D"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_un));
        te1 = view.findViewById(R.id.textView7);
        te1.setTextColor(Color.parseColor("#F87210"));
        te1.setBackground(getResources().getDrawable(R.drawable.full_corner_se));
        if (taskTimeText == true) {
            taskTime.setText("1天");
            taskTime.setTextColor(Color.parseColor("#FF000000"));
        }
        if (audioTimeText == true) {
            audioTime.setText("1天");
            audioTime.setTextColor(Color.parseColor("#FF000000"));
        }
    }

    public void onClick_back(View view) {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            popupWindow = null;
            mIsShowing = false;
            params.alpha = 1f;
            taskTimeText = false;
            audioTimeText = false;
            getWindow().setAttributes(params);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            popupWindow = null;
            mIsShowing = false;
            params.alpha = 1f;
            getWindow().setAttributes(params);
        }
        return super.onTouchEvent(event);
    }

    private void uploadfile(String url) {
        RequestParams params = new
                RequestParams("http://192.168.43.173:8080/FileUpload/FileUploadServlet"
        );
        //// 使用 multipart 表单上传文件
        params.setMultipart(true);
        String prefix = UUID.randomUUID().toString().replace("-", "");
        imgFile = prefix + ".jpg";
        params.addBodyParameter("file", new
                        File(url),
                null, imgFile);

        Log.i("upload", Environment.getExternalStorageDirectory().toString());
        x.http().post(params, new Callback.ProgressCallback<File>() {
            @Override
            public void onSuccess(File result) {
                Log.i("onSuccess-上传文件成功", result.toString());
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                LogUtil.e("onError-下载文件失败" + ex.getMessage());
            }

            @Override
            public void onCancelled(CancelledException cex) {
                LogUtil.e("onCancelled-");
            }

            @Override
            public void onFinished() {
                LogUtil.e("onFinished-");
            }

            @Override
            public void onWaiting() {
                LogUtil.e("onWaiting-");
            }

            @Override
            public void onStarted() {
                LogUtil.e("onStarted-");
            }

            @Override
            public void onLoading(long total, long current, boolean
                    isDownloading) {
//                progressBar.setMax((int) total);
//                progressBar.setProgress((int) current);
                LogUtil.e("onLoading-" + current + "/" + total);
            }
        });
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case 100:
                boolean writeExternalStorage = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                boolean readExternalStorage = grantResults[1] == PackageManager.PERMISSION_GRANTED;
                if (grantResults.length > 0 && writeExternalStorage && readExternalStorage) {
                    getImage();
                } else {
                    Toast.makeText(this, "请设置必要权限", Toast.LENGTH_SHORT).show();
                }

                break;
        }
    }

    private void getImage() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
                    REQUEST_PICK_IMAGE);
        } else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, REQUEST_PICK_IMAGE);
        }
    }

}